<template>
    <view class="container" :style="themeColor">
        <header-bar :config="config"></header-bar>
        <product-temp
            ref="productTemp"
            :tempType="0"
            :isOnShow="isOnShow"
            @upCart="upCart"
            :classifyID="classifyID"
            :tabindexID="tabindexID"
            :productTagId="productTagId"
            :productBrandId="productBrandId"></product-temp>
    </view>
</template>

<script>
import productTemp from "@/pages/product/productTemp.vue"
import storage from "@/uni-sub-base/utils/storage.js"
import { getUserCarList } from "@/utils/cartUtil.js"
export default {
    components: {
        productTemp,
    },
    props: {
        visible: {
            type: Boolean,
            default: false,
        },
    },
    watch: {
        visible: {
            handler(newVal) {
                if (newVal) {
                    this.setStatusBarStyle("dark")
                    setTimeout(() => {
                        this.$refs.productTemp.getListHeight(true)
                        this.viewInit()
                    }, 100)
                }
            },
            immediate: true,
        },
        refresh(e) {
            if (e) {
            }
        },
    },
    data() {
        return {
            isOnShow: true,
            productTagId: "",
            productBrandId: "",
            classifyID: "",
            tabindexID: 0,
            config: {
                title: "商品",
                back: false,
                centerSlot: true,
                barPlaceholder: true,
            },
        }
    },
    methods: {
        viewInit() {
            this.isOnShow = true
            let productTagId = storage.getCache("productTagId")
            let productBrandId = storage.getCache("productBrandId")
            let classifyID = storage.getCache("classifyID")
            let tabindexID = storage.getCache("tabindexID")

            if (productTagId) {
                this.productTagId = productTagId + ""
                this.$forceUpdate()
                setTimeout((e) => {
                    storage.removeCache("productTagId")
                    this.productTagId = ""
                }, 3000)
            }
            if (productBrandId) {
                this.productBrandId = productBrandId + ""
                this.$forceUpdate()
                setTimeout((e) => {
                    storage.removeCache("productBrandId")
                    this.productBrandId = ""
                }, 3000)
            }
            if (classifyID) {
                this.classifyID = classifyID + ""
                this.$forceUpdate()
                setTimeout((e) => {
                    storage.removeCache("classifyID")
                    this.classifyID = ""
                }, 3000)
            }
            if (tabindexID) {
                this.tabindexID = tabindexID
                this.$forceUpdate()
                setTimeout((e) => {
                    storage.removeCache("tabindexID")
                    this.tabindexID = 0
                }, 3000)
            }
            this.$forceUpdate()
        },
        proInit() {
            let webInfo = storage.getCache("webInfo")
            if (this.getAppSet().isSubBusiness) {
                this.config.title = webInfo.BusinessName
            }
        },
        upCart(isOnShow) {
            this.isOnShow = isOnShow
            //离开页面 同步购物车  TODO 增加条件 有变更 再同步
            getUserCarList().then((res) => {
                this.isChangeCart = false
            })
        },
    },
    mounted() {
        this.proInit()
    },
}
</script>

<style lang="scss"></style>
